Skip to content

Conversation

@h2ls
Copy link
Collaborator

@h2ls h2ls commented Jun 3, 2025

Link issues

fixes #6144

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Enable configurable zoom speed in the image viewer components by introducing a ZoomSpeed parameter, validating its value, and integrating it into mouse and keyboard zoom logic with proper event handler disposal.

New Features:

  • Add ZoomSpeed parameter to ImageViewer and ImagePreviewer components to customize zoom sensitivity

Enhancements:

  • Validate zoomSpeed in the viewer module and fall back to a default speed when invalid or non-positive
  • Use zoomSpeed (with a finer step when holding Shift) for mouse wheel zoom operations
  • Properly register and dispose the keyboard event handler to avoid residual listeners

Documentation:

  • Update sample usage in ImageViewers.razor to demonstrate the new ZoomSpeed parameter

h2ls and others added 4 commits June 3, 2025 15:32
Introduced a new `ZoomSpeed` property in `ImagePreviewer.razor.cs` to allow configuration of the preview zoom speed, marked with the `[Parameter]` attribute for parent component usage.
@bb-auto
Copy link

bb-auto bot commented Jun 3, 2025

Thanks for your PR, @h2ls. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jun 3, 2025

Reviewer's Guide

This PR adds a new ZoomSpeed parameter to the ImageViewer and ImagePreviewer components, propagates it into the underlying viewer.js module (with a fallback BASE_SPEED), replaces hardcoded wheel zoom increments with the configurable speed (including a slower Shift-key variant), and adjusts event handler registration and disposal accordingly.

Sequence Diagram for ZoomSpeed Initialization Process

sequenceDiagram
    participant IV_Component as "ImageViewer (C#)"
    participant IP_Component as "ImagePreviewer (C#)"
    participant IP_JS as "ImagePreviewer.razor.js"
    participant Viewer_JS as "viewer.js"

    IV_Component->>IP_Component: Set ZoomSpeed property (e.g., 0.5)
    activate IP_Component
    IP_Component->>IP_Component: OnAfterRenderAsync / InvokeInitAsync() logic executes
    IP_Component->>IP_JS: init(id, prevList, { ZoomSpeed: 0.5 })
    deactivate IP_Component
    activate IP_JS
    IP_JS->>Viewer_JS: Viewer.init(el, prevList, { ZoomSpeed: 0.5 })
    deactivate IP_JS
    activate Viewer_JS
    Viewer_JS->>Viewer_JS: viewer.zoomSpeed = config.zoomSpeed (0.5)
    Viewer_JS->>Viewer_JS: Validate viewer.zoomSpeed (if invalid or <=0, use BASE_SPEED)
    deactivate Viewer_JS
Loading

Sequence Diagram for Mouse Wheel Zoom Operation

sequenceDiagram
    actor User
    participant PrevImgElement as "Image Element (in DOM)"
    participant Viewer_JS as "viewer.js (handlerWheel)"

    User->>PrevImgElement: Scrolls mouse wheel
    activate PrevImgElement
    PrevImgElement->>Viewer_JS: mousewheel/DOMMouseScroll event (e)
    deactivate PrevImgElement
    activate Viewer_JS
    Viewer_JS->>Viewer_JS: Read viewer.zoomSpeed (configured value)
    Viewer_JS->>Viewer_JS: Read e.shiftKey
    Viewer_JS->>Viewer_JS: Calculate zoomStep based on viewer.zoomSpeed and e.shiftKey
    alt e.wheelDelta > 0 (or equivalent for zoom in)
        Viewer_JS->>Viewer_JS: newScale = currentScale + zoomStep
    else (zoom out)
        Viewer_JS->>Viewer_JS: newScale = Math.max(minScale, currentScale - zoomStep)
    end
    Viewer_JS->>Viewer_JS: Call processImage(newScale) to apply zoom
    deactivate Viewer_JS
Loading

File-Level Changes

Change Details Files
Introduce ZoomSpeed parameter in Blazor components
  • Add nullable ZoomSpeed parameter to ImagePreviewer and ImageViewer .razor.cs
  • Pass ZoomSpeed through InvokeVoidAsync in ImagePreviewer initialization
  • Bind ZoomSpeed attribute in ImageViewer markup and sample usage
ImagePreviewer.razor.cs
ImageViewer.razor.cs
ImageViewer.razor
ImageViewers.razor
Enhance viewer.js to use configurable zoom speed
  • Define BASE_SPEED fallback and validate config.zoomSpeed
  • Compute per-wheel zoomStep and support Shift for slower zoom
  • Replace hardcoded 0.015 increments with zoomStep in handlerWheel
wwwroot/modules/viewer.js
Propagate config to the JS initializer
  • Update ImagePreviewer.razor.js init signature to accept config
  • Forward ZoomSpeed in Viewer.init call
ImagePreviewer.razor.js
Refine event handler lifecycle in viewer module
  • Assign document keydown to viewer.keyHandler and unregister it in dispose
  • Remove redundant comments and streamline EventHandler.off calls
wwwroot/modules/viewer.js

Assessment against linked issues

Issue Objective Addressed Explanation
#6144 Introduce a new parameter ZoomSpeed to dynamically adjust the zoom increment per mouse wheel step.
#6144 Modify the wheel event handler to apply ZoomSpeed instead of a hardcoded value.
#6144 Ensure backward compatibility (retain current behavior if ZoomSpeed is unset).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot requested a review from ArgoZhang June 3, 2025 11:45
@bb-auto bb-auto bot added the enhancement New feature or request label Jun 3, 2025
@bb-auto bb-auto bot added this to the 9.7.0 milestone Jun 3, 2025
@h2ls h2ls marked this pull request as draft June 3, 2025 11:46
sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 3, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @h2ls - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented Jun 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (5acba45) to head (a84aafc).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #6145   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          703       703           
  Lines        31088     31090    +2     
  Branches      4395      4395           
=========================================
+ Hits         31088     31090    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Enhance the `ImagePreviewer` in `ImageViewer.razor` by introducing a new `ZoomSpeed` parameter, allowing users to adjust the zoom speed when displaying images. This update also includes the addition of the `ZoomSpeed` property in `ImageViewer.razor.cs`, making it publicly accessible and documented for better usability.
h2ls added 2 commits June 3, 2025 19:57
Updated the definition of the `BASE_SPEED` constant to use the nullish coalescing operator (`??`) instead of a ternary operator. This change simplifies the code by ensuring `BASE_SPEED` is set to `viewer.zoomSpeed` if defined, or defaults to `0.015` if not. Retained the existing comment for context.
@h2ls h2ls marked this pull request as ready for review June 3, 2025 12:07
@h2ls
Copy link
Collaborator Author

h2ls commented Jun 3, 2025

@dotnet-policy-service agree
@microsoft-github-policy-service agree

sourcery-ai[bot]
sourcery-ai bot previously approved these changes Jun 3, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @h2ls - I've reviewed your changes - here's some feedback:

  • Verify that the ZoomSpeed value from the config object is actually attached to the viewer instance inside the init function; without assigning it (e.g. viewer.zoomSpeed = config.ZoomSpeed), the JS fallback will always be used.
  • Consider validating or clamping the ZoomSpeed parameter (ensure it’s positive and within a reasonable range) in the C# component or JS to prevent zero or excessively high zoom rates.
  • You may want to give the C# ZoomSpeed parameter a default value (e.g. 0.015) so the default behavior is explicit in the API surface rather than relying solely on the JS fallback.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang
Copy link
Member

@sourcery-ai review

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @h2ls - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit 2df033c into main Jun 4, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the lee/imageview branch June 4, 2025 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ImageViewer): support change zoomSpeed

3 participants